﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.OleDb;
using System.Text;
using System.Data;
using DTO;
using DAO;

namespace BUS
{
    public class LoaiSachBUS
    {
        public static DataTable layFullLoaiSach()
        {

            return LoaiSachDAO.layFullLoaiSach();
        }
        public static Boolean themLoaiSach(LoaiSachDTO ls)
        {
            return LoaiSachDAO.themLoaiSach(ls);
        }
        public static int kiemTra(LoaiSachDTO ls)
        {
            if (ls.TenLoaiSach == "")
                return 1;
            if (ls.TienTo == "")
                return 2;
            if (ls.Thue == null)
                return 3;
            return 0;
        }

        public static Boolean xoaLoaiSach(int id)
        {
            return LoaiSachDAO.xoaLoaiSach(id);
        }
        public static Boolean updateLoaiSach(LoaiSachDTO ls)
        {
            return LoaiSachDAO.updateLoaiSach(ls);
        }
        public static Boolean kiemTraCheckbox(Boolean f1, Boolean f2, Boolean f3)
        {
            if (f1 == false && f2 == false && f3 == false)
                return false;
            return true;
        }
        public static DataTable timKiem(Boolean f1, Boolean f2, Boolean f3, String str)
        {
            String strQuery = "select * from LoaiSach ";
            if (f1 == true)
                strQuery += string.Format("where tenLoaiSach LIKE '%{0}%'", str);
            if (f1 == true && f2 == true)
                strQuery += string.Format("OR tienTo LIKE '%{0}%'", str);
            if (f1 == false && f2 == true)
                strQuery += string.Format("where tienTo LIKE '%{0}%'", str);
            if ((f1 == true || f2 == true) && f3 == true)
                strQuery += string.Format("OR maSachCapNhat LIKE '%{0}%'", str);
            if (f1 == false && f2 == false && f3 == true)
                strQuery += string.Format("where maSachCapNhat LIKE '%{0}%'", str);
            return LoaiSachDAO.timKiem(strQuery);
        }
    }
}
